//
//  M1RangeSliderTrackLayer.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/17.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1RangeSliderTrackLayer.h"
#import "M1RangeSlider.h"

@implementation M1RangeSliderTrackLayer

- (void)drawInContext:(CGContextRef)ctx
{
    // clip  给layer绘制圆角
    float cornerRadius = self.bounds.size.height * self.m1_slider.m1_curvaceousness / 2.0;
    UIBezierPath *switchOutline = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                                             cornerRadius:cornerRadius];
    CGContextAddPath(ctx, switchOutline.CGPath);
    CGContextClip(ctx);
    
    // 1) fill the track 给整个layer填充颜色
    CGContextSetFillColorWithColor(ctx, self.m1_slider.m1_trackColour.CGColor);
    CGContextAddPath(ctx, switchOutline.CGPath);
    CGContextFillPath(ctx);
    
    // 2) fill the highlighed range 计算两个滑块的位置，并把滑块中间的轨迹填充高亮的颜色
    CGContextSetFillColorWithColor(ctx, self.m1_slider.m1_trackHighlightColour.CGColor);
    float lower = [self.m1_slider m1_positionForValue:self.m1_slider.m1_lowerValue];
    float upper = [self.m1_slider m1_positionForValue:self.m1_slider.m1_upperValue];
    CGContextFillRect(ctx, CGRectMake(lower, 0, upper - lower, self.bounds.size.height));

}

@end
